package blog.action;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;

import blog.entity.Article;
import blog.entity.Comment;
import blog.entity.Link;
import blog.entity.Notice;
import blog.enums.ArticleStatus;
import blog.enums.LinkStatus;
import blog.enums.NoticeStatus;
import blog.service.ArticleService;
import blog.service.CommentService;
import blog.service.LinkService;
import blog.service.NoticeService;

/**
 * 分类
 * 
 * @author 14560
 *
 */
@Controller
public class CategoryAction {
	// 文章信息
	@Resource
	private ArticleService articleService;

	// 评论信息
	@Resource
	private CommentService commentService;

	// 友情链接
	@Resource
	private LinkService linkService;

	// 公告
	@Resource
	private NoticeService noticeService;

	@RequestMapping(value = "/category/{categoryId}")
	public String index(@PathVariable("categoryId") Integer categoryId,
			@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
			@RequestParam(required = false, defaultValue = "10") Integer pageSize, ModelMap m) {
		
		HashMap<String, Object> paramMap = new HashMap<>(1);
		paramMap.put("status", ArticleStatus.PUBLISH.getValue());
		paramMap.put("categoryId",categoryId);

		// 文章列表
		PageInfo<Article> articleList = articleService.getPageArticleList(pageIndex, pageSize, paramMap);
		m.put("pageInfo", articleList);
		m.put("pageUrlPrefix", "/category/"+categoryId+"?pageIndex");

		// 最新评论
		List<Comment> recentCommentList = commentService.listRecentComment(10);
		m.put("recentCommentList", recentCommentList);

		// 友情链接(在framework.jsp中做的显示)
		List<Link> linkList = linkService.listLink(LinkStatus.NORMAL.getValue());
		m.put("linkList", linkList);

		// 公告
		List<Notice> noticeList = noticeService.listNotice(NoticeStatus.NORMAL.getValue());
		m.put("noticeList", noticeList);

		return "index";
	}
}
